/*
 * Copyright 2010 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.dnd;

import de.mnit.basis.daten.ArrayHilfe;
import de.mnit.basis.daten.struktur.gruppe.Gruppe2;
import de.mnit.basis.daten.struktur.menge.Menge;
import de.mnit.basis.daten.struktur.menge.S_Menge;
import de.mnit.basis.fehler.Fehler;

/**
 * @author Michael Nitsche
 * 13.06.2010	Erstellt
 *
 * http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html
 */
public abstract class A_DND_Basis {

	protected final DNDART[] arten;
	protected final DNDTYP[] typen;


	protected A_DND_Basis(S_DND... dnd) {
		Gruppe2<DNDART[],DNDTYP[]> g =dndSplit(dnd);
		this.arten=g.g1();
		this.typen=g.g2();
		Fehler.bereich.wenn_ZuKurz(1, (Object[])this.arten);
		Fehler.bereich.wenn_ZuKurz(1, (Object[])this.typen);
	}


	public DNDART[] gArten() { return this.arten; }
	public DNDTYP[] gTypen() { return this.typen; }

	public boolean kennt(DNDTYP typ) {
		return ArrayHilfe.kennt(typen, typ);
	}

	private Gruppe2<DNDART[],DNDTYP[]> dndSplit(S_DND[] dnd) {
		S_Menge<DNDART> mArt=Menge.neu();
		S_Menge<DNDTYP> mTyp=Menge.neu();
		for(S_DND d : dnd)
			if(d instanceof DNDART)
				mArt.plus((DNDART)d);
			else mTyp.plus((DNDTYP)d);
		return Gruppe2.neu(mArt.zuArray(DNDART.class),mTyp.zuArray(DNDTYP.class));
	}

}
